package com.ssu.judea.travlog.view;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MyOverLay extends Overlay {
	private GeoPoint gp1;
	private GeoPoint gp2;
	private int mRadius = 6;
	private int mode = 0;
	private boolean isEndPoint = false;

	public MyOverLay(GeoPoint gp1, GeoPoint gp2, int mode, boolean isEndPoint) // GeoPoint is a int.// (6E)
	{
		this.gp1 = gp1;
		this.gp2 = gp2;
		this.mode = mode;
		this.isEndPoint = isEndPoint;
	}

	public int getMode() {
		return mode;
	}

	public boolean draw(Canvas canvas, MapView mapView, boolean shadow,	long when) {
		Projection projection = mapView.getProjection();
		if (shadow == false) {
			Paint paint = new Paint();
			paint.setAntiAlias(true);
			Point point = new Point();
			projection.toPixels(gp1, point);
			Point point2 = new Point();
			projection.toPixels(gp2, point2);
			// mode=1&#65306;start
			if (mode == 0) {
				paint.setColor(Color.GREEN);
				RectF oval = new RectF(point.x - mRadius, point.y - mRadius,
						point.x + mRadius, point.y + mRadius);
				canvas.drawOval(oval, paint);
			}
			// mode=1&#65306;start
			else if (mode == 1) {
				paint.setColor(Color.BLUE);
				RectF oval = new RectF(point.x - mRadius, point.y - mRadius,
						point.x + mRadius, point.y + mRadius);
				canvas.drawOval(oval, paint);
			}
			// mode=2&#65306;path
			else if (mode == 2) {
				paint.setColor(0x660000FF);
				
				
				paint.setStrokeWidth(5);
				paint.setAlpha(120);
				canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
			}
			/* mode=3&#65306;end */
			else if (mode == 3 && isEndPoint) {
				paint.setColor(Color.RED);
				canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
				RectF oval = new RectF(point2.x - mRadius, point2.y - mRadius,
						point2.x + mRadius, point2.y + mRadius);
				canvas.drawOval(oval, paint);
			}
		}
		return super.draw(canvas, mapView, shadow, when);
	}
}
